import { ref, onMounted } from 'vue'
import { getAllEventHttp, putEventsStatusHttp } from '../../request/eventHttp'

export const useEventAlreafyAuditStore = () => {
  const tableAlreadyEventData = ref([])
  const currentPage = ref(1)
  const pageSize = ref(5)
  const total = ref()

  // 获取所有已审核是事件分页数据
  const fetchAlreadyEventData = async () => {
    const res = await getAllEventHttp(currentPage.value, pageSize.value, '', '2')
    if (res.data.code === 0) {
      tableAlreadyEventData.value = res.data.data
      total.value = res.data.total
    }
  }

  // 分页器size
  const handleSizeChange = (val) => {
    pageSize.value = val
    fetchAlreadyEventData()
  }

  // 分页器page
  const handleCurrentChange = (val) => {
    currentPage.value = val
    fetchAlreadyEventData()
  }

  // 加载事件数据
  onMounted(() => {
    fetchAlreadyEventData()
  })

  return {
    tableAlreadyEventData,
    currentPage,
    pageSize,
    total,
    handleSizeChange,
    handleCurrentChange
  }
}
